package com.eyas.business.config.webmvc.exception.resolver;

import com.eyas.business.config.webmvc.exception.custom.uncheck.EyasBusinessException;
import com.eyas.business.config.webmvc.exception.exceptionmodel.uncheck.EyasBusinessDTO;
import com.eyas.core.jdbc.utils.JdbcTempleteException;
import org.h2.jdbc.JdbcSQLException;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import java.sql.SQLException;

/**
 * @Auther: 王龙龙
 * @Date: 2019/2/28 17:01
 * @Description:
 */
@RestControllerAdvice
public class CommonExceptionResolver {

    @ExceptionHandler(EyasBusinessException.class)
    @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
    public EyasBusinessDTO HandlerEyasBusinessExceptionResolver(EyasBusinessException e) {
        e.printStackTrace();
        EyasBusinessDTO resultdto = new EyasBusinessDTO();
        resultdto.setErrormsg(e.getMessage());
        return resultdto;
    }

    @ExceptionHandler(SQLException.class)
    @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
    public EyasBusinessDTO HandlerSQLExceptionResolver(SQLException e) {
        e.printStackTrace();
        EyasBusinessDTO resultdto = new EyasBusinessDTO();
        resultdto.setErrormsg("后台sql出错，请联系管理员查看日志");
        return resultdto;
    }

    @ExceptionHandler(JdbcTempleteException.class)
    @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
    public EyasBusinessDTO HandlerJdbcTempleteExceptionResolver(JdbcTempleteException e) {
        e.printStackTrace();
        EyasBusinessDTO resultdto = new EyasBusinessDTO();
        resultdto.setErrormsg("数据查询内部驱动程序出错，请联系管理员查看日志");
        return resultdto;
    }
}
